package com.le.tester.leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * currentTime:2022/3/12 10:10
 * description:包含重复的元素plus
 */
public class ContainsNearbyDuplicate {
    public boolean containsNearbyDuplicate(int[] nums, int k) {
        Map<Integer, Integer> map = new HashMap<>();
        int length = nums.length;

        for (int i = 0; i < length; i++) {
            int num = nums[i];
            if (map.containsKey(num) && i - map.get(num) <= k) {
                return true;
            }
            map.put(num, i);
        }
        return false;

    }

    public static void main(String[] args) {
        ContainsNearbyDuplicate containsNearbyDuplicate = new ContainsNearbyDuplicate();
        containsNearbyDuplicate.containsNearbyDuplicate(new int[]{1, 2, 3, 1}, 3);

    }
}
